package com.ctshk.rpc.workflow.mapper;

import com.ctshk.rpc.workflow.base.CustomBaseMapper;
import com.ctshk.rpc.workflow.entity.SysApprovalSetting;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 审批配置表 Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-25
 */
public interface SysApprovalSettingMapper extends CustomBaseMapper<SysApprovalSetting> {

    /**
     * 根据业务类型和审批类型获取指定用户所能使用的审批
     * @param businessType
     * @param approvalType
     * @param deptIds
     * @return
     */
    @Select("<script>"+"SELECT tsas.* FROM `t_sys_approval_setting` tsas" +
            " LEFT JOIN t_sys_approval_setting_sponsor tsass ON tsass.setting_id = tsas.id" +
            " WHERE tsas.business_type = #{businessType}" +
            " AND tsas.approval_type = #{approvalType}" +
            " AND tsas.is_deleted = 0" +
            " AND tsass.sponsor_object_id in <foreach collection='deptIds' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            " LIMIT 1"+
            "</script>")
    SysApprovalSetting getSettingByType(@Param("businessType") long businessType, @Param("approvalType")  long approvalType, @Param("deptIds") List<Long> deptIds);
}
